package hongcaosp.app.android.contact.friends;

import java.util.ArrayList;
import java.util.List;

import hongcaosp.app.android.common.IListView;
import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.bean.ContactListWrapper;
import hongcaosp.app.android.modle.bean.IUser;
import hongcaosp.app.android.modle.impl.UserModleImpl;
import hongcaosp.app.android.modle.mi.UserModle;
import xlj.lib.android.base.component.BasePresenter;

public class MyFriendsPresenter extends BasePresenter {
    private IListView<IUser> listView;
    private UserModle userModle;

    public MyFriendsPresenter(IListView<IUser> listView) {
        this.listView = listView;
        userModle = new UserModleImpl();
    }

    public void fresh() {
        userModle.goodFriends(UserToken.getDefault().getToken(), new DataCallBack<ContactListWrapper>() {
            @Override
            public void onGetData(ContactListWrapper data) {
                super.onGetData(data);
                List<IUser> userList = new ArrayList<>();
                if (data.getGoodFriend() != null) {
                    userList.addAll(data.getGoodFriend());
                }
                listView.freshList(userList,false);
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
                listView.freshList(null,false);
            }
        });
    }
}
